home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gcc / libnix.lha / gnu / lib / libnix / sources.lha / detach / bcback20.S < prev    next >
Encoding:
Text File  |  1994-06-11  |  2.7 KB  |  163 lines

  1. | auto-detaching baserelative startup code for gcc v2.3.3
  2. | (c) by M.Fleischer and G.Nikl Sat May 28 11:55 1994
  3. | No real bugs known but requires v37
  4.  
  5. | some specific defines
  6.  
  7. _LVOForbid    =    -132
  8. _LVOPermit    =    -138
  9. _LVOFindTask    =    -294
  10. _LVOGetMsg    =    -372
  11. _LVOReplyMsg    =    -378
  12. _LVOWaitPort    =    -384
  13. _LVOCloseLibrary =    -414
  14. _LVOOpenLibrary    =    -552
  15.  
  16. _LVOCreateNewProc =    -498
  17. _LVOCli        =    -492
  18.  
  19. pr_MsgPort    =      92
  20. pr_CLI        =     172
  21.  
  22. cli_Module    =      60
  23.  
  24. RETURN_OK    =       0
  25. RETURN_FAIL    =      20
  26.  
  27. | public symbols
  28.  
  29.         .globl    ___subexit
  30.         .globl    _geta4
  31.  
  32.         .text
  33.  
  34. | first entry - init some vars, check for cli or wb start
  35.  
  36. start:        movel    a0,d3
  37.  
  38.         jbsr    _geta4
  39.  
  40.         movel    sp,a4@(_SaveSP:W)
  41.         movel    4:W,a6
  42.         movel    a6,a4@(_SysBase:W)
  43.  
  44.         subal    a1,a1
  45.         jsr    a6@(_LVOFindTask:W)
  46.         movel    d0,a3
  47.  
  48.         tstl    a4@(_DetachFlag:W)
  49.         bnes    fromCLI
  50.  
  51.         tstl    a3@(pr_CLI:W)
  52.         bne    Detach
  53.  
  54. | wb start - get wbmsg
  55.  
  56. fromWB:        lea    a3@(pr_MsgPort:W),a0
  57.         jsr    a6@(_LVOWaitPort:W)
  58.         lea    a3@(pr_MsgPort:W),a0
  59.         jsr    a6@(_LVOGetMsg:W)
  60.         movel    d0,a4@(__WBenchMsg:W)
  61.  
  62. | call __submain()
  63.  
  64. fromCLI:    movel    d3,a4@(___commandline:W)
  65.         jmp    ___submain
  66.  
  67. | __subexit() entry - get return val, restore stackptr
  68.  
  69. ___subexit:    movel    a4@(__WBenchMsg:W),d2
  70.         beqs    todos
  71.         jsr    a6@(_LVOForbid:W)
  72.         movel    d2,a1
  73.         jsr    a6@(_LVOReplyMsg:W)
  74.  
  75. todos:        movel    sp@(4:W),d0
  76.         movel    a4@(_SaveSP:W),sp
  77.         rts
  78.  
  79. | get baseptr
  80.  
  81. _geta4:        lea    ___a4_init,a4
  82.         rts
  83.  
  84. | detach the process from the shell task
  85.  
  86. NP_Seglist    =    0x800003e9
  87. NP_FreeSeglist    =    0x800003ea
  88. NP_StackSize    =    0x800003f3
  89. NP_Name        =    0x800003f4
  90. NP_Arguments    =    0x800003fd
  91.  
  92. Detach:        lea    a4@(___dosname:W),a1
  93.         moveq    #37,d0
  94.         jsr    a6@(_LVOOpenLibrary:W)
  95.  
  96. | need a private DOSBase !!!
  97.  
  98.         movel    d0,d6
  99.         beq    nodos
  100.  
  101. | get pointer to CommandLineInterface (need not dereference BPTR)
  102.  
  103.         exg    d6,a6
  104.         jsr    a6@(_LVOCli:W)
  105.         movel    d0,a3
  106.         exg    d6,a6
  107.  
  108. | create process with disabled multitasking !!!
  109.  
  110.         jsr    a6@(_LVOForbid:W)
  111.  
  112. | save original stackpointer and setup required taglist
  113.  
  114.         movel    sp,a2
  115.         clrl    sp@-
  116.         movel    d3,sp@-
  117.         pea    NP_Arguments
  118.         movel    a4@(__procname:W),sp@-
  119.         pea    NP_Name
  120.         movel    a4@(__stack:W),d0
  121.         beqs    defstack
  122.         movel    d0,sp@-
  123.         pea    NP_StackSize
  124. defstack:    pea    1:W
  125.         pea    NP_FreeSeglist
  126.         movel    a3@(cli_Module:W),sp@-
  127.         pea    NP_Seglist
  128.         movel    sp,d1
  129.         exg    d6,a6
  130.         jsr    a6@(_LVOCreateNewProc:W)
  131.         exg    d6,a6
  132.         movel    a2,sp
  133.         movel    d0,a4@(_DetachFlag:W)
  134.         beqs    noproc
  135.  
  136. | clear cli_Module to prevent unloading by the shell
  137.  
  138.         clrl    a3@(cli_Module:W)
  139.  
  140. | reenable multitasking - all done or maybe not ...
  141.  
  142. noproc:        jsr    a6@(_LVOPermit:W)
  143.  
  144. | close dos.library
  145.  
  146.         movel    d6,a1
  147.         jsr    a6@(_LVOCloseLibrary:W)
  148.  
  149. | exit graceful
  150.  
  151. nodos:        moveq    #RETURN_OK,d0
  152.         rts
  153.  
  154. | data area
  155.  
  156.         .data
  157.  
  158. .lcomm        _SaveSP,4
  159. .lcomm        _DetachFlag,4
  160. .comm        _SysBase,4
  161. .comm        __WBenchMsg,4
  162. .comm        ___commandline,4
  163.